import { defineStore } from 'pinia';
import type { ClassifyWallList } from '../api/classify';
import { ref } from 'vue';

export const useClassifyListStore = defineStore('classifyList', () => {
  const list = ref<(ClassifyWallList & { picurl: string })[]>([]);
  function setList(data: ClassifyWallList[]) {
    list.value = data.map(item => {
      return {
        ...item,
        picurl: item.smallPicurl.replace('_small.webp', '.jpg'),
      };
    });
  }
  function setUserScore(id: string, score: string) {
    list.value.find(item => {
      const flag = item._id === id;
      if (flag) {
        item.userScore = score;
      }
      return flag;
    });
  }

  return { list, setList, setUserScore };
});
